package src.E_Thread;

// 线程强制执行，join合并线程，待此线程执行完成后，再执行其他线程，其他线程阻塞，可以想象成插队
public class E11_ThreadJoin implements Runnable{
    @Override
    public void run() {
        try {
            Thread.sleep(1000);
            for (int i = 0; i < 20; i++) {
                System.out.println("梦梦来了，都给我闪开！"+i);
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new E11_ThreadJoin());
        thread.start();
        for (int i = 0; i < 100; i++) {
            if (i == 20){
                System.out.println("突然");
                thread.join();
                System.out.println("梦梦走咯！");
            }
            System.out.println("我正在散步。。。"+i);
        }
    }
}
